package com.caidan.search.service.impl;

import com.caidan.common.result.Result;
import com.caidan.common.util.AuthContextHolder;
import com.caidan.model.vo.index.IndexVo;
import com.caidan.search.mapper.IndexMapper;
import com.caidan.search.service.IndexService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * @项目名 CaiDanSearchSystem
 * @描述
 * @作者 小菜蛋
 * @时间 2024/12/2 19:26
 */
@Service
public class IndexServiceImpl implements IndexService {
    @Resource
    private IndexMapper indexMapper;

    @Override
    public Result<IndexVo> getStatus() {
        Long userId = AuthContextHolder.getUserId();
        if (userId == null || userId <= 0) {
            return this.defaultInfoMessage();
        }
        System.out.println("用户ID = " + userId);
        // user set background img
        // 用户是否登录 用户是否
        IndexVo indexVo = indexMapper.getStatus(userId);
        if (indexVo == null) {
            return this.defaultInfoMessage();
        }
        indexVo.setLoggedIn(true);
        return Result.ok(indexVo);
    }

    private Result<IndexVo> defaultInfoMessage() {
        IndexVo indexVo = new IndexVo();
        indexVo.setBackgroundImage("http://124.71.148.150:9001/api/v1/buckets/cdatguiguts/objects/download?preview=true&prefix=fee80f9084444c44b847622e1ba5760e&version_id=null");
        indexVo.setProfilePictureUrl("http://124.71.148.150:9001/api/v1/buckets/hamos/objects/download?preview=true&prefix=5d5f43c0b2364119b6b6599cb981ed63.jpg&version_id=null");
        indexVo.setUsername("未登录");
        indexVo.setLoggedIn(false);
        return Result.ok(indexVo);
    }
}
